import { queryUesrList } from '@/pages/BTCList/service';
import { Select } from 'antd';
import React from 'react';
import { queryUse } from '@/utils/service';

// const utMap = {1:"期现套利",2:"网格",3:"现货",4:"流动挖矿"}
export const getSelectList: any = async (userType: string, mainId: string, actionRef: any) => {
  const attach = queryUse(await queryUesrList(Number(userType)));
  let selects: any[] = [];
  const { Option } = Select;
  let idList: (string | number | null)[] = [];
  if (attach) {
    if (userType === '2') {
      selects.push(<Option value={'全部'}>全部</Option>);
      idList.push('全部');
      localStorage.setItem(mainId + 'ParamId', '全部');
    }
    attach.map((a: { nickname: string; id: number; name: string }) => {
      idList.push(a.id.toString());
      selects.push(<Option value={a.id.toString()}>{a.nickname}</Option>);
    });
    if (idList.indexOf(localStorage.getItem(mainId + 'ParamId')) === -1) {
      localStorage.setItem(mainId + 'ParamId',(attach[0]? attach[0].id:'').toString());
    }
  }
  return (
    <div>
      账户选择：{' '}
      <Select
        style={{ width: '200px', marginRight: '20px' }}
        defaultValue={localStorage.getItem(mainId + 'ParamId') as string}
        onSelect={e => {
          localStorage.setItem(mainId + 'ParamId', e.toString());
          actionRef.current.reload();
        }}
      >
        {selects ? selects : null}
      </Select>
    </div>
  );
};
